<?php
Class Lie_Comments
{
/*How many comments in the day*/
var $segment_size=4;
/*How many days to show*/
var $show_days=5;
var $data; 
var $new_data;
var $data_count;
var $today;
var $total=0;
var $days;
    function Lie_Comments($today,$data)
    {
        $this->today=$today;    
        $this->data=  ($data);
        $this->data_count=count($this->data);
        $august1=strtotime("2013-06-01");
        $this->days=ceil(($today-$august1)/86400);
       
    }
    function draw_comments()
    {
        
        $e_persent=(floor((($this->days/$this->data_count)-floor($this->days/$this->data_count))*100)*$this->segment_size)+($this->show_days*$this->segment_size);

        $day=$this->today;
      
        $j=$this->segment_size-1;
        $out='';
        if($e_persent>=$this->data_count)
        {
            $a_start=($e_persent+1)-floor($e_persent/$this->data_count)*$this->data_count;
               $out.=$this->roll($a_start,$this->today);
            
            
            if($this->total<($this->segment_size*$this->show_days))
            {
               $a_start=$this->data_count;
               $out.=$this->roll($a_start,$day);
            }
          
          
        }else{
            $a_start=($e_persent+1);
            $out.=$this->roll($a_start,$day);
        }
        return $out;
        
    }
    function roll($a_start,$day)
    {
         $out='';
         $a_end=$a_start-($this->segment_size*$this->show_days);
         if($this->total)$a_end+=$this->total;
        for($a=($a_start-1);$a>=($a_end);$a--)
           {
   
               if(isset($this->data[$a]))
                   {
                   $out.=$this->draw_comment($this->data[$a], $day);
                   $this->new_data[$day][]=$this->data[$a];
                   $this->total++;
                   }
               if(count($this->new_data[$day])==$this->segment_size)
                   { 
                   $day-=86400; 
                   }
           }
     return $out;
        
    }
    function draw_comment($d,$day)
    {
    #global $total;
    
    $html.='
    ID: '.$d['id'].'<br>
    Title: '.$d['title'].'<br>
    Content: '.$d['content'].'<br>
    RelTime:'.$d['reltime'].'<br>
    Date: '.date('d-m-Y',$day).'<hr>';
    return $html;
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$data[0]=array('id'=>0,'title'=>"The heading 0",'content'=>"text text text...",'reltime'=>1);
$data[1]=array('id'=>1,'title'=>"The heading 1",'content'=>"text text text...",'reltime'=>2);
$data[2]=array('id'=>2,'title'=>"The heading 2",'content'=>"text text text...",'reltime'=>3);
$data[3]=array('id'=>3,'title'=>"The heading 3",'content'=>"text text text...",'reltime'=>4);
$data[4]=array('id'=>4,'title'=>"The heading 4",'content'=>"text text text...",'reltime'=>5);
$data[5]=array('id'=>5,'title'=>"The heading 5",'content'=>"text text text...",'reltime'=>6);
$data[6]=array('id'=>6,'title'=>"The heading 6",'content'=>"text text text...",'reltime'=>7);
$data[7]=array('id'=>7,'title'=>"The heading 7",'content'=>"text text text...",'reltime'=>8);
$data[8]=array('id'=>8,'title'=>"The heading 8",'content'=>"text text text...",'reltime'=>9);
$data[9]=array('id'=>9,'title'=>"The heading 9",'content'=>"text text text...",'reltime'=>10);
$data[10]=array('id'=>10,'title'=>"The heading 10",'content'=>"text text text...",'reltime'=>1);
$data[11]=array('id'=>11,'title'=>"The heading 11",'content'=>"text text text...",'reltime'=>2);
$data[12]=array('id'=>12,'title'=>"The heading 12",'content'=>"text text text...",'reltime'=>3);
$data[13]=array('id'=>13,'title'=>"The heading 13",'content'=>"text text text...",'reltime'=>4);
$data[14]=array('id'=>14,'title'=>"The heading 14".$i,'content'=>"text text text...",'reltime'=>5);
$data[15]=array('id'=>15,'title'=>"The heading 15".$i,'content'=>"text text text...",'reltime'=>6);
$data[16]=array('id'=>16,'title'=>"The heading 16".$i,'content'=>"text text text...",'reltime'=>7);
$data[17]=array('id'=>17,'title'=>"The heading 17".$i,'content'=>"text text text...",'reltime'=>8);
$data[18]=array('id'=>18,'title'=>"The heading 18".$i,'content'=>"text text text...",'reltime'=>0);
$data[19]=array('id'=>19,'title'=>"The heading 19".$i,'content'=>"text text text...",'reltime'=>10);
$data[20]=array('id'=>20,'title'=>"The heading 20".$i,'content'=>"text text text...",'reltime'=>1);
$data[21]=array('id'=>21,'title'=>"The heading 21".$i,'content'=>"text text text...",'reltime'=>2);
$data[22]=array('id'=>22,'title'=>"The heading 22".$i,'content'=>"text text text...",'reltime'=>3);
$data[23]=array('id'=>23,'title'=>"The heading 23".$i,'content'=>"text text text...",'reltime'=>4);
$data[24]=array('id'=>24,'title'=>"The heading 24".$i,'content'=>"text text text...",'reltime'=>5);
$data[25]=array('id'=>25,'title'=>"The heading 25".$i,'content'=>"text text text...",'reltime'=>6);
$data[26]=array('id'=>26,'title'=>"The heading 26".$i,'content'=>"text text text...",'reltime'=>7);
$data[27]=array('id'=>27,'title'=>"The heading 27".$i,'content'=>"text text text...",'reltime'=>8);
$data[28]=array('id'=>28,'title'=>"The heading 28".$i,'content'=>"text text text...",'reltime'=>9);
$data[29]=array('id'=>29,'title'=>"The heading 29".$i,'content'=>"text text text...",'reltime'=>10);
$data[30]=array('id'=>30,'title'=>"The heading 30".$i,'content'=>"text text text...",'reltime'=>1);
$data[31]=array('id'=>31,'title'=>"The heading 31".$i,'content'=>"text text text...",'reltime'=>2);
$data[32]=array('id'=>32,'title'=>"The heading 32".$i,'content'=>"text text text...",'reltime'=>3);
$data[33]=array('id'=>33,'title'=>"The heading 33".$i,'content'=>"text text text...",'reltime'=>4);
$data[34]=array('id'=>34,'title'=>"The heading 34".$i,'content'=>"text text text...",'reltime'=>5);
$data[35]=array('id'=>35,'title'=>"The heading 35".$i,'content'=>"text text text...",'reltime'=>6);
$data[36]=array('id'=>36,'title'=>"The heading 36".$i,'content'=>"text text text...",'reltime'=>7);
$data[37]=array('id'=>37,'title'=>"The heading 37".$i,'content'=>"text text text...",'reltime'=>8);
$data[38]=array('id'=>38,'title'=>"The heading 38".$i,'content'=>"text text text...",'reltime'=>9);
$data[39]=array('id'=>39,'title'=>"The heading 39".$i,'content'=>"text text text...",'reltime'=>10);
$data[40]=array('id'=>40,'title'=>"The heading 40".$i,'content'=>"text text text...",'reltime'=>1);
$data[41]=array('id'=>41,'title'=>"The heading 41".$i,'content'=>"text text text...",'reltime'=>2);
$data[42]=array('id'=>42,'title'=>"The heading 42".$i,'content'=>"text text text...",'reltime'=>3);
$data[43]=array('id'=>43,'title'=>"The heading 43".$i,'content'=>"text text text...",'reltime'=>4);
$data[44]=array('id'=>44,'title'=>"The heading 44".$i,'content'=>"text text text...",'reltime'=>5);
$data[45]=array('id'=>45,'title'=>"The heading 45".$i,'content'=>"text text text...",'reltime'=>6);
$data[46]=array('id'=>46,'title'=>"The heading 46".$i,'content'=>"text text text...",'reltime'=>7);
$data[47]=array('id'=>47,'title'=>"The heading 47".$i,'content'=>"text text text...",'reltime'=>8);
$data[48]=array('id'=>48,'title'=>"The heading 48".$i,'content'=>"text text text...",'reltime'=>9);
$data[49]=array('id'=>49,'title'=>"The heading 49".$i,'content'=>"text text text...",'reltime'=>10);
$data[50]=array('id'=>50,'title'=>"The heading 50".$i,'content'=>"text text text...",'reltime'=>1);
$data[51]=array('id'=>51,'title'=>"The heading 51".$i,'content'=>"text text text...",'reltime'=>2);
$data[52]=array('id'=>52,'title'=>"The heading 52".$i,'content'=>"text text text...",'reltime'=>3);
$data[53]=array('id'=>53,'title'=>"The heading 53".$i,'content'=>"text text text...",'reltime'=>4);
$data[54]=array('id'=>54,'title'=>"The heading 54".$i,'content'=>"text text text...",'reltime'=>5);
$data[55]=array('id'=>55,'title'=>"The heading 55".$i,'content'=>"text text text...",'reltime'=>6);
$data[56]=array('id'=>56,'title'=>"The heading 56".$i,'content'=>"text text text...",'reltime'=>7);
$data[57]=array('id'=>57,'title'=>"The heading 57".$i,'content'=>"text text text...",'reltime'=>8);
$data[58]=array('id'=>58,'title'=>"The heading 58".$i,'content'=>"text text text...",'reltime'=>9);
$data[59]=array('id'=>59,'title'=>"The heading 59".$i,'content'=>"text text text...",'reltime'=>10);
$data[60]=array('id'=>60,'title'=>"The heading 60".$i,'content'=>"text text text...",'reltime'=>1);
$data[61]=array('id'=>61,'title'=>"The heading 61".$i,'content'=>"text text text...",'reltime'=>2);
$data[62]=array('id'=>62,'title'=>"The heading 62".$i,'content'=>"text text text...",'reltime'=>3);
$data[63]=array('id'=>63,'title'=>"The heading 63".$i,'content'=>"text text text...",'reltime'=>4);
$data[64]=array('id'=>64,'title'=>"The heading 64".$i,'content'=>"text text text...",'reltime'=>5);
$data[65]=array('id'=>65,'title'=>"The heading 65".$i,'content'=>"text text text...",'reltime'=>6);
$data[66]=array('id'=>66,'title'=>"The heading 66".$i,'content'=>"text text text...",'reltime'=>7);
$data[67]=array('id'=>67,'title'=>"The heading 67".$i,'content'=>"text text text...",'reltime'=>8);
$data[68]=array('id'=>68,'title'=>"The heading 68".$i,'content'=>"text text text...",'reltime'=>9);
$data[69]=array('id'=>69,'title'=>"The heading 69".$i,'content'=>"text text text...",'reltime'=>10);
$data[70]=array('id'=>70,'title'=>"The heading 70".$i,'content'=>"text text text...",'reltime'=>1);
$data[71]=array('id'=>71,'title'=>"The heading 71".$i,'content'=>"text text text...",'reltime'=>2);
$data[72]=array('id'=>72,'title'=>"The heading 72".$i,'content'=>"text text text...",'reltime'=>3);
$data[73]=array('id'=>73,'title'=>"The heading 73".$i,'content'=>"text text text...",'reltime'=>4);
$data[74]=array('id'=>74,'title'=>"The heading 74".$i,'content'=>"text text text...",'reltime'=>5);
$data[75]=array('id'=>75,'title'=>"The heading 75".$i,'content'=>"text text text...",'reltime'=>6);
$data[76]=array('id'=>76,'title'=>"The heading 76".$i,'content'=>"text text text...",'reltime'=>7);
$data[77]=array('id'=>77,'title'=>"The heading 77".$i,'content'=>"text text text...",'reltime'=>8);
$data[78]=array('id'=>78,'title'=>"The heading 78".$i,'content'=>"text text text...",'reltime'=>9);
$data[79]=array('id'=>79,'title'=>"The heading 79".$i,'content'=>"text text text...",'reltime'=>10);
$data[80]=array('id'=>80,'title'=>"The heading 80".$i,'content'=>"text text text...",'reltime'=>1);
$data[81]=array('id'=>81,'title'=>"The heading 81".$i,'content'=>"text text text...",'reltime'=>2);
$data[82]=array('id'=>82,'title'=>"The heading 82".$i,'content'=>"text text text...",'reltime'=>3);
$data[83]=array('id'=>83,'title'=>"The heading 83".$i,'content'=>"text text text...",'reltime'=>4);
$data[84]=array('id'=>84,'title'=>"The heading 84".$i,'content'=>"text text text...",'reltime'=>5);
$data[85]=array('id'=>85,'title'=>"The heading 85".$i,'content'=>"text text text...",'reltime'=>6);
$data[86]=array('id'=>86,'title'=>"The heading 86".$i,'content'=>"text text text...",'reltime'=>7);
$data[87]=array('id'=>87,'title'=>"The heading 87".$i,'content'=>"text text text...",'reltime'=>8);
$data[88]=array('id'=>88,'title'=>"The heading 88".$i,'content'=>"text text text...",'reltime'=>9);
$data[89]=array('id'=>89,'title'=>"The heading 89".$i,'content'=>"text text text...",'reltime'=>10);
$data[90]=array('id'=>90,'title'=>"The heading 90".$i,'content'=>"text text text...",'reltime'=>1);
$data[91]=array('id'=>91,'title'=>"The heading 91".$i,'content'=>"text text text...",'reltime'=>2);
$data[92]=array('id'=>92,'title'=>"The heading 92".$i,'content'=>"text text text...",'reltime'=>3);
$data[93]=array('id'=>93,'title'=>"The heading 93".$i,'content'=>"text text text...",'reltime'=>4);
$data[94]=array('id'=>94,'title'=>"The heading 94".$i,'content'=>"text text text...",'reltime'=>5);
$data[95]=array('id'=>95,'title'=>"The heading 95".$i,'content'=>"text text text...",'reltime'=>6);
$data[96]=array('id'=>96,'title'=>"The heading 96".$i,'content'=>"text text text...",'reltime'=>7);
$data[97]=array('id'=>97,'title'=>"The heading 97".$i,'content'=>"text text text...",'reltime'=>8);
$data[98]=array('id'=>98,'title'=>"The heading 98".$i,'content'=>"text text text...",'reltime'=>9);
$data[99]=array('id'=>99,'title'=>"The heading 99".$i,'content'=>"text text text...",'reltime'=>10);
$data[100]=array('id'=>99,'title'=>"The heading 100".$i,'content'=>"text text text...",'reltime'=>10);
$data[101]=array('id'=>101,'title'=>"The heading 101".$i,'content'=>"text text text...",'reltime'=>10);
$data[102]=array('id'=>102,'title'=>"The heading 102".$i,'content'=>"text text text...",'reltime'=>10);
$data[103]=array('id'=>103,'title'=>"The heading 103".$i,'content'=>"text text text...",'reltime'=>10);
### today value ### 
if(isset($_GET['today']))
{
$today=strtotime($_GET['today']);
}else{
$today=time();
}
#die($today."<hr>");
$lc=new Lie_Comments($today,$data);
 echo $lc->draw_comments();
print '<h5>'.$lc->total.'</h5>';
?>
